package dao

import (
	"fmt"
	__ "hospital-srv/basic/proto"
	"hospital-srv/handler/models"
)

// 品牌添加
func BrandAdd(in *__.BrandAddReq) (*models.Brand, error) {
	var brand models.Brand
	brand.BrandName = in.BrandName               //品牌名称
	brand.BrandLogo = in.BrandLogo               //品牌logo
	brand.BrandDescription = in.BrandDescription //品牌描述
	err := brand.BrandAdd()
	if err != nil {
		return nil, fmt.Errorf("品牌添加失败")
	}
	return &brand, nil
}

// 品牌删除
func BrandDel(in *__.BrandDelReq) (*models.Brand, error) {
	var brand models.Brand
	brand.Id = in.Id
	err := brand.BrandDel()
	if err != nil {
		return nil, fmt.Errorf("品牌删除失败")
	}
	return &brand, nil
}

// 品牌修改
func BrandUpdate(in *__.BrandUpdateReq) (*models.Brand, error) {
	var brand models.Brand
	brand.Id = in.Id
	brand.BrandName = in.BrandName
	brand.BrandLogo = in.BrandLogo
	brand.BrandDescription = in.BrandDescription
	err := brand.BrandUpdate()
	if err != nil {
		return nil, fmt.Errorf("品牌修改失败")
	}
	return &brand, nil
}

// 品牌展示
func BrandFind(in *__.BrandFindReq) ([]*__.BrandFind, error) {
	var brand models.Brand
	var brandList []*__.BrandFind
	find, err := brand.BrandFind()
	if err != nil {
		return nil, err
	}
	for _, b := range find {
		brandList = append(brandList, &__.BrandFind{
			Id:               b.Id,
			BrandName:        b.BrandName,
			BrandLogo:        b.BrandLogo,
			BrandDescription: b.BrandDescription,
		})
	}
	return brandList, nil
}

// 品牌详情
func BrandDetails(in *__.BrandDetailsReq) (*models.Brand, error) {
	var brand models.Brand
	brand.Id = in.Id
	err := brand.BrandDetails()
	if err != nil {
		return nil, err
	}

	return &brand, nil
}
